<html>
<head><meta charset="utf-8"><title>Find if an item is publicly reachable? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html">Find if an item is publicly reachable?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214926662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/214926662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#214926662">(Oct 29 2020 at 04:55)</a>:</h4>
<p>Rustdoc currently rewrites this from scratch with <code>inside_public_path</code>: <a href="https://github.com/rust-lang/rust/blob/master/src/librustdoc/visit_ast.rs#L421">https://github.com/rust-lang/rust/blob/master/src/librustdoc/visit_ast.rs#L421</a>. Is there a query for this?</p>



<a name="214926707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/214926707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#214926707">(Oct 29 2020 at 04:56)</a>:</h4>
<p><code>is_unreachable_local_definition</code> looks promising</p>



<a name="217579509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579509">(Nov 23 2020 at 00:53)</a>:</h4>
<p>I know it's like a month later but I still have the same question :/ it turns out <code>is_unreachable</code> isn't right because it's worrying about link-time reachability, so it thinks glob imports are unreachable</p>



<a name="217579560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579560">(Nov 23 2020 at 00:54)</a>:</h4>
<p>I guess I can see how <code>unreachable_pub</code> does this, but IIRC unreachable_pub is buggy itself</p>



<a name="217579577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579577">(Nov 23 2020 at 00:55)</a>:</h4>
<p>great, the thing it's buggy on is glob imports <span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>



<a name="217579689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579689">(Nov 23 2020 at 00:58)</a>:</h4>
<p><code>privacy_access_levels(LOCAL_CRATE).is__reachable()</code> might be right?</p>



<a name="217579696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579696">(Nov 23 2020 at 00:58)</a>:</h4>
<p>nope, same bugs on glob imports</p>



<a name="217579890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217579890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217579890">(Nov 23 2020 at 01:03)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> how hard would it be to fix <a href="https://github.com/rust-lang/rust/pull/57922#discussion_r251234129">https://github.com/rust-lang/rust/pull/57922#discussion_r251234129</a> ? Is it something I could work on myself?</p>



<a name="217580015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217580015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217580015">(Nov 23 2020 at 01:06)</a>:</h4>
<p>if it helps, rustdoc seems to have roughly the right algorithm in <code>visit_ast</code>, see everywhere using <code>inside_public_path</code>: <a href="https://github.com/rust-lang/rust/blob/a0d664bae6ca79c54cc054aa2403198e105190a2/src/librustdoc/visit_ast.rs#L155">https://github.com/rust-lang/rust/blob/a0d664bae6ca79c54cc054aa2403198e105190a2/src/librustdoc/visit_ast.rs#L155</a></p>



<a name="217580401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217580401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217580401">(Nov 23 2020 at 01:15)</a>:</h4>
<p>(the reason I want to fix this is so I can get rid of rustdoc's reachability pass, which currently has no relation at all to what rustc thinks is reachable)</p>



<a name="217580899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217580899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217580899">(Nov 23 2020 at 01:26)</a>:</h4>
<p>actually I may have misunderstood what's going on here - the test that's failing is <a href="https://github.com/rust-lang/rust/blob/98e16884b10630e6e6ef5f4a076af3409122401d/src/test/rustdoc/inline_local/glob-private.rs#L8">https://github.com/rust-lang/rust/blob/98e16884b10630e6e6ef5f4a076af3409122401d/src/test/rustdoc/inline_local/glob-private.rs#L8</a>, which rustdoc thinks is private but rustc thinks is public. Even though those imports are visible from the crate root, they're not visible <em>at that path</em>, only at the root, e.g. <code>crate::Mod2Public</code> is valid but <code>crate::mod1::Mod2</code> is not because <code>mod1</code> is private</p>



<a name="217673300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217673300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217673300">(Nov 23 2020 at 19:40)</a>:</h4>
<blockquote>
<p>how hard would it be to fix <a href="https://github.com/rust-lang/rust/pull/57922#discussion_r251234129">https://github.com/rust-lang/rust/pull/57922#discussion_r251234129</a> ?</p>
</blockquote>
<p>Medium hard... I guess?<br>
I don't know. I probably need to half-implement this myself to estimate.</p>
<blockquote>
<p>Is it something I could work on myself?</p>
</blockquote>
<p>Well, you certainly can try.</p>



<a name="217673894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217673894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217673894">(Nov 23 2020 at 19:45)</a>:</h4>
<p>On the infrastructure side, resolve should build a table containing <code>Public</code> and <code>Exported</code> sets (as <a href="https://github.com/rust-lang/rust/pull/57922#discussion_r251234129">https://github.com/rust-lang/rust/pull/57922#discussion_r251234129</a> says) and put that table into <code>ResolverOutputs</code>, from there it will be available to <code>tcx</code> and anything using it.<br>
Then <code>rustc_privacy</code> will be able to start from the <code>Exported</code> set rather than from scratch and build the <code>Reachable</code> and <code>ReachableFromImplTrait</code> sets by itself.</p>



<a name="217673896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217673896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217673896">(Nov 23 2020 at 19:45)</a>:</h4>
<p>I cannot provide any details on the "build a table containing <code>Public</code> and <code>Exported</code> sets" right now though.</p>



<a name="217674286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20if%20an%20item%20is%20publicly%20reachable%3F/near/217674286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20if.20an.20item.20is.20publicly.20reachable.3F.html#217674286">(Nov 23 2020 at 19:48)</a>:</h4>
<p>Thanks! It turns out I didn't need this for <a href="https://github.com/rust-lang/rust/pull/77467">https://github.com/rust-lang/rust/pull/77467</a> so I probably won't get to it right away but hopefully I'll have time over winter break.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>